package com.itfreer.utils.common;

import java.io.InputStream;
import java.util.Properties;

import android.content.Context;

/**
 * 配置文件工具类
 */
public class PropertiesUtils extends Properties {

    private static Properties property = new Properties();

    /**
     * 获取属性值
     * @param context
     * @param fileName
     * @param key
     * @return
     */
    public static String readAssetsProp(Context context,String fileName, String key) {
        String value = "";
        try {
            InputStream in = context.getAssets().open(fileName);
            property.load(in);
            value = property.getProperty(key);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        return value;
    }

    /**
     * 获取属性值
     * @param context
     * @param fileName
     * @param key
     * @param defaultValue
     * @return
     */
    public static String readAssetsProp(Context context,String fileName, String key,String defaultValue) {
        String value = "";
        try {
            InputStream in = context.getAssets().open(fileName);
            property.load(in);
            value = property.getProperty(key, defaultValue);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        return value;
    }
}